HTMLify

index.html
Views: 61 | Author: cody
<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Colorful Ripple Effect</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='style.css'>
</head>

<body>

    <a href="#" class="btn">Click Me</a>

    <script>
        let btn = document.querySelectorAll(".btn");
        btn.forEach((btn) => {
            btn.onclick = function (e) {
                let x = e.pageX - e.target.offsetLeft;
                let y = e.pageY - e.target.offsetTop;

                let color = "#" + Math.floor(Math.random() * 0xffffff).toString(16);

                let ripples = document.createElement("span");
                ripples.style.left = x + "px";
                ripples.style.top = y + "px";
                ripples.style.borderColor = color;
                this.appendChild(ripples);

                setTimeout(() => {
                    ripples.remove();
                }, 2000);
            };
        });
    </script>
</body>

</html>

Comments